package cn.dansj.repository;

import cn.dansj.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;

@Repository
public interface UserRepository extends JpaRepository<User, String>, JpaSpecificationExecutor<User> {

    @Query(value = "select t from User t where t.username=:identifier or t.sequence=:identifier or t.mail=:identifier or t.mobile=:identifier")
    User getUser(@Param("identifier") String identifier);

    User findUserBySequence(String sequence);

    @Modifying
    @Query(value = "update User t set t.status = :status,t.updateTime=:update_time where t.sequence = :sequence")
    void updateStatus(@Param("sequence") String sequence,
                      @Param("status") String status,
                      @Param("update_time") Timestamp update_time);

    User findUserByToken(String token);
}